#!/bin/bash
#=======================
# Author : Ali Moradzade
# Created: 2022/01/29
#=======================

# factmail mailing the answer to a factorial

MAIL=$(which mailx)

factorial=1
counter=1

read -p "Enter the number: " value
while [ $counter -le $value ]
do
	factorial=$[ $factorial * $counter ]
	counter=$[ $counter + 1 ]
done

echo The factorial of $value is $factorial | $MAIL -s "Factorial answer" $USER
echo "The result has beed mailed to you."
